//
//  BaseViewController.swift
//  CWLiving
//
//  Created by 方正刚 on 2017/7/13.
//  Copyright © 2017年 方正刚. All rights reserved.
//

import UIKit
import ImageIO
import QuartzCore

class BaseViewController: UIViewController {

    
    var contentView: UIView?
    var images = [UIImage]()

    lazy var animationView: UIImageView = {
        
         let animationV = UIImageView()
             animationV.frame = CGRect(x: (SCREEN_WIDHT - 160) / 2, y: (contentHeight - 180) / 2, width: 160, height: 180)
        
         let gifPath = Bundle.main.path(forResource: "fishWomen.gif", ofType: nil)
        
         let gitData = NSData(contentsOfFile: gifPath!)
        
         let gifDataSource: CGImageSource = CGImageSourceCreateWithData(gitData! as CFData, nil)!
        
         let gifImageCount: Int = CGImageSourceGetCount(gifDataSource)
        
        
        for i in 0...gifImageCount - 1 {
            
            let imageref:CGImage? = CGImageSourceCreateImageAtIndex(gifDataSource, i, nil)
            
            let image: UIImage = UIImage(cgImage: imageref!)
            
            self.images.append(image)
        }
        
        return animationV

        }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
        
    }
       
}




extension BaseViewController {
    
    func setupUI() {
        view.backgroundColor = UIColor(r: 250, g: 250, b: 250)
        contentView?.isHidden = true
        view.addSubview(animationView)
        animationView.animationImages = images
        animationView.animationDuration = 0.5
        animationView.startAnimating()

    }
    

    func didLoadData() {
        animationView.stopAnimating()
        animationView.isHidden = true
        contentView?.isHidden = false
        
    }
    
    
}
    
    
    

